<template>
<div>
  <el-row class="c1">
    <el-col :span="6" :offset="9">
      <div class="c2"><br><br>
        <el-form ref="form" :model="stu" label-width="60px">
          <el-form-item label="用户名">
            <el-input v-model="stu.sname"></el-input>
          </el-form-item>
          <!--    <el-form-item label="密码">-->
          <!--      <el-input type="textarea" v-model="form.desc"></el-input>-->
          <!--    </el-form-item>-->
          <el-form-item>
            <el-button type="primary" @click="onSubmit">登录</el-button>
          </el-form-item>
        </el-form>
      </div>
    </el-col>
  </el-row>
</div>
</template>

<script>
import axios from "axios";
export default {
  name: "Login",
  data() {
    return {
      stu:{
        sname:"",//和后端一致

      }
    }
  },
  methods: {
    onSubmit(){
      //console.log(this.stu.sname);
      // axios.post("/login",{},{
      //   params:{username:this.stu.sname}
      // })
      //登录建议使用post
      axios.post("/login",{
        sname:this.stu.sname
      }).then(ret=>{
        if(ret.code==2000){
          this.$message({
            message:"登录成功",
            type:"success",
            duration:700
          })
          //登录成功跳转主页
          this.$router.push("/admin")
        }else{
          this.$message({
            message:"登录失败",
            type:"error",
            duration:700
          })
        }
      })
    }
  }
}
</script>


<style scoped>
.c1{
  margin-top: 240px;
}
.c2{
  border: cyan 2px solid;
  width: 300px;
  height: 200px;
}

</style>